#pragma once

#include <libge/libge.h>
#include <vector>
#include "Chunk.h"
#include "Material.h"
#include "Location.h"
#include "Entity.h"
#include "Painting.h"

#define SOLO 0
#define MULTI 1

#define NORTH 0
#define SOUTH 1
#define EAST 2
#define WEST 3
#define UP 4
#define DOWN 5

class Client;
class Block;

class World {
public:
	World(Client* cli, u32 seed, int max_view);
	~World();

	const Location& getSpawn();
	void setSpawn(Location loc);
	int getGameMode();
	void setGameMode(int gm);
	std::vector<Entity*>* getEntities();
	void SpawnEntity(Entity* e);
	Entity* SpawnEntity(int id, int type, Location loc);
	Entity* SpawnObject(int id, int type, Location loc);
	Entity* getEntityById(int id);
	void DestroyEntity(int id);
	Chunk* getChunks();
	u32 getChunksCount();
	Chunk* FindChunk(int x, int y);
	Chunk* GetUnusedChunk();
	Chunk* GetMostAwayChunk(int x, int y);
	Chunk* ReserveChunk();
	Block* FindBlock(int x, int y, int z);
	Block* FindBlock(int x, int y, int z, Chunk** chunk);

private:
	Client* client;
	Location spawn;
	int gameMode;
	Chunk* chunks;
	u32 nChunks;
	std::vector<Entity*> entities;
};


/*

	int spawn_x, spawn_y, spawn_z;
	int game_mode;
	Player player;

	int day_ticks;

	Resources* res;
	struct {
		bool fullscreen;
		bool multicore;
		int seed;
		int view_distance;
	} options;

	Chunk* chunks;
	int nChunks;
	int* rchunks;
	int nRchunks;
	
	ge_GuiWindow* win;
	ge_GuiButton* b_up;
	ge_GuiButton* b_down;
	ge_GuiButton* b_forward;
	ge_GuiButton* b_backward;
	ge_GuiButton* b_left;
	ge_GuiButton* b_right;

	ge_Keys* keys;
	ge_Camera* cam;
	ge_Light* sun;

	ge_Thread* chunksthid;
	ge_Thread* gamethid;
	ge_Thread* ctrlthid;
	*/
